<!DOCTYPE HTML>
<html lang="en">
<head>
<title>AutoTrim - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The AutoTrim command determines whether traditional assignments like Var1 = %Var2% omit spaces and tabs from the beginning and end of Var2." />
<meta name="ahk:equiv-v2" content="commands/Trim.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>AutoTrim</h1>

<p>Determines whether <a href="SetEnv.htm">traditional assignments</a> like <code>Var1 = %Var2%</code> omit spaces and tabs from the beginning and end of <em>Var2</em>.</p>

<pre class="Syntax"><span class="func">AutoTrim</span>, OnOff</pre>
<h2>Parameters</h2>
<dl>

  <dt>OnOff</dt>
  <dd><p><strong>On</strong>: In a <a href="SetEnv.htm">traditional assignment</a> like <code>Var1 = %Var2%</code>, tabs and spaces at the beginning and end of a <em>Var2</em> are omitted from <em>Var1</em>. This is the default.</p>
      <p id="Off"><strong>Off</strong>: Such tabs and spaces are not omitted.</p>
      <p><span class="ver">[v1.1.30+]:</span> The decimal values 1 and 0 may be used in place of On and Off, respectively.</p>
      <p>Any literal tabs and spaces are omitted regardless of this setting. Prior to <span class="ver">[v1.1.06]</span>, this included `t and any escaped literal spaces or tabs. For example, when AutoTrim is Off, the statement <code>Var = `t</code> assigns a tab character on <span class="ver">[v1.1.06]</span> and an empty string on earlier versions.</p></dd>

</dl>

<h2>Remarks</h2>
<p>If this command is not used by a script, the setting defaults to ON.</p>
<p>The built-in variable <strong>A_AutoTrim</strong> contains the current setting (On or Off).</p>
<p>The built-in variables <a href="../Variables.htm#Space">A_Space</a> and <a href="../Variables.htm#Tab">A_Tab</a> contain a single space and single tab character, respectively.</p>
<p>AutoTrim does not affect <a href="SetExpression.htm">expression assignments</a> such as <code>Var := &quot; string &quot;</code>. In other words, leading and trailing spaces and tabs are always retained in such cases.</p>
<p>Every newly launched <a href="../misc/Threads.htm">thread</a> (such as a <a href="../Hotkeys.htm">hotkey</a>, <a href="Menu.htm">custom menu item</a>, or <a href="SetTimer.htm">timed</a> subroutine) starts off fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).</p>
<h2>Related</h2>
<p><a href="SetEnv.htm">SetEnv</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>AutoTrim, Off
NewVar1 = %OldVar%  <em>; If OldVar contains leading and trailing spaces, NewVar will have them too.</em>
NewVar2 = %A_Space%  <em>; With AutoTrim off, a single space can be assigned this way.</em>

Var1 := &quot;`t&quot; <strong>.</strong> Var2 <strong>.</strong> &quot; &quot;  <em>; The setting of AutoTrim doesn't matter because this is an <a href="../Variables.htm#Expressions">expression</a>.</em></pre>
</div>

</body>
</html>
